﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shsc.Net.Common.Validator.Validators;

namespace Shsc.Net.Common.Validator.Attributes
{

    [AttributeUsage(AttributeTargets.Property)]
    public class MinLengthAttribute : BaseValidationAttribute
    {
        /// <summary>
        /// 
        /// </summary>
        private string ERROR_MESSAGE_ID = "HE_90006";

        /// <summary>
        /// 最大长度
        /// </summary>
        public int MinLength { get; set; }

        /// <summary>
        /// 是否按字节查看
        /// </summary>
        public bool IsByte { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="minLength"></param>
        public MinLengthAttribute(int minLength)
        {
            MinLength = minLength;
            IsByte = false;
            this.ErrorMessageId = ERROR_MESSAGE_ID;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="minLength"></param>
        /// <param name="isByte"></param>
        public MinLengthAttribute(int minLength, bool isByte)
        {
            MinLength = minLength;
            IsByte = isByte;

            this.ErrorMessageId = ERROR_MESSAGE_ID;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        protected override Shsc.Net.Common.Validator.Validators.BaseValidator CreateValidator()
        {
            if (ErrorMessageParam == null
                || ErrorMessageParam.Length == 0)
            {
                this.ErrorMessageParam = new String[] { Convert.ToString(MinLength) };
            }
            return new MinLengthValidator();
        }
    }
}
